
const baseURL = 'https://api-hmugo-web.itheima.net/api/public/v1'
let requestCount = 0;
const request = ({ url, ...config }) => {
    requestCount++
    wx.showNavigationBarLoading()
    if (url.startsWith('/my')) {
        const token = uni.getStorageSync('token')
        config.header = {Authorization:token}
    }
    return new Promise((resolve, reject) => {
        uni.request({
           ...config,
           url: baseURL + url,
           success: (res) => {
               resolve(res)
           },
           fail: (err)=>{
               reject(err)
            },
            complete: () => {
                requestCount--
                if (requestCount === 0) {
                    wx.hideNavigationBarLoading()
                }
            }
       });
    })
}
export default request